package com.database.service.impl;


import com.database.character.UserAccount;
import com.database.mapper.UserMapper;
import com.database.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

  @Autowired
  private UserMapper userMapper;

  @Override
  public UserAccount login(UserAccount userAccount) {
    return userMapper.getByNicknameAndPassword(userAccount);
  }

  @Override
  public int addUser(UserAccount userAccount) {
    userAccount.setUpdateTime(LocalDateTime.now());
    userAccount.setRegisterTime(LocalDate.now());
    return userMapper.addUser(userAccount);
  }

  @Override
  public int updateUser(UserAccount userAccount) {
    userAccount.setUpdateTime(LocalDateTime.now());
    return userMapper.updateUser(userAccount);
  }

  @Override
  public int deleteUserByUid(Integer userId) {
    return userMapper.deleteUserByUid(userId);
  }

  @Override
  public List<UserAccount> list() {
    return userMapper.list();
  }

  @Override
  public UserAccount getByUid(Integer userId) {
    return userMapper.getByUid(userId);
  }

  @Override
  public UserAccount getByNickname(String nickname) {
    return userMapper.getByNickname(nickname);
  }
}
